package com.gxa.uhome.util;

import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author: Laiguowei
 * @date: 16:01 2021/6/10
 **/
public class UploadUtil {

  public static String getFileName(MultipartFile file) {


      String fileName =file.getOriginalFilename();//获得上传图片的名称
      int i = fileName.indexOf(".");
      String lastFileName = fileName.substring(i);
      UUID uuid = UUID.randomUUID();
      String stringUuid = String.valueOf(uuid);
      String replace = stringUuid.replace("-", "");
      lastFileName = replace + lastFileName;
        return lastFileName;

  }

}
